﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
using System;
using Microsoft.Xna.Framework;
namespace Z2.Core
{

	#region Using

	#endregion

	/// <summary>
	/// Základní třída pro definování chování objektu
	/// </summary>
	internal abstract class ObjectBehaviorBase
	{

		#region Constructor

		/// <summary>
		/// Konstruktor
		/// </summary>
		protected ObjectBehaviorBase()
		{
		}

		#endregion

		#region Methods

		/// <summary>
		/// Metoda, která modifikuje vektor pohybu objektu <paramref name="obj"/>
		/// </summary>
		/// <param name="obj"><see cref="ObjectBase"/></param>
		internal abstract void ModifyVector(ObjectBase obj);

		internal virtual void PerfomActionsOn(ObjectBase objOn, ObjectBase obj, IntersectionResult intersection)
		{
		}

		internal virtual void NormalizeVector(ObjectBase obj)
		{
			if (obj.Move.X > 0)
			{
				obj.Move = new Vector2(obj.Move.X - ObjectBase.FRICTION_DEFAULT, obj.Move.Y);
			}
			if (obj.Move.X < 0)
			{
				obj.Move = new Vector2(obj.Move.X + ObjectBase.FRICTION_DEFAULT, obj.Move.Y);
			}

			if (obj.HorizontalState != ObjectStateHorizontal.Idle &&
				Math.Round(obj.Move.X, 0, MidpointRounding.ToEven) == 0)
			{
				obj.HorizontalState = ObjectStateHorizontal.Idle;
				obj.Move = new Vector2(0, obj.Move.Y);
				obj.Change = new Vector2(0, obj.Move.Y);
				obj.OnStopMovingHorizontal();
			}
		}
		
		#endregion

	}
}
